package dp.command.invoker;

import dp.command.command.Command;
import dp.command.command.impl.NoCommand;

public class RemoteController {

	Command[] onCommands;
	Command[] offCommands;
	Command undoCommand;
	
	public RemoteController() {
		onCommands = new Command[8];
		offCommands = new Command[8];
		undoCommand = new NoCommand();
		for(int i=0;i<8;i++)
		{
			onCommands[i] = new NoCommand();
			offCommands[i] = new NoCommand();
		}
	}
	
	public void setCommand(int slot, Command onCommand, Command offCommand) {
		onCommands[slot] = onCommand;
		offCommands[slot] = offCommand;
	}
	
	public void onButtonPushed(int number){
		onCommands[number].execute();
		undoCommand = offCommands[number];
	}
	
	public void offButtonPushed(int number){
		offCommands[number].execute();
		undoCommand = onCommands[number];
	}
	
	public void undoButtonPushed() {
		undoCommand.execute();
	}
	
	public String toString() {
		StringBuffer stringBuff = new StringBuffer();
		stringBuff.append("\n------ Remote Controller ------\n");
		for (int i=0; i<onCommands.length; i++)
		{
			stringBuff.append("[slot "+i+"] " + onCommands[i].getClass().getName()+"  " + offCommands[i].getClass().getName()+"\n");
		}
		return stringBuff.toString();
	}
	
}
